$(function(){
    eneryChart();
});
//累计能耗
var xdata=[];
var ydata=[];
function eneryChart() {

    $.ajax({
        type : "get",
        url : "eneryTotal",
        dataType : "json",
        data : {id:currentcarid},
        success : function(data) {
            xdata=[];
            ydata=[];
            for (var en in data) {
                xdata.push(data[en].resetCount);
                ydata.push(data[en].energy/3600000);
            }
            showChart(xdata,ydata);
        },error:function(errmsg){
            alert("Ajax获取服务器数据出错了！"+ errmsg);
        }
    });
}
function showChart() {
    var myenChart = echarts.init(document.getElementById('energy'));
    option = {
        title: {
            text: '累计能耗',
            x: 'center'
        },
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        xAxis: {
            name : '复位次数',
            type: 'category',
            data: xdata//[1, 2, 3, 4, 5, 6, 7]
        },
        yAxis: {
            name : '累计能耗(kW.h)',
            type: 'value'
        },
        series: [{
            data: ydata,//[120, 200, 150, 80, 70, 110, 130],
            type: 'bar'
        }]
    };
    myenChart.setOption(option);
}